package dcc.component.tabs;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JTable;

import dcc.mbg.model.MAttendPoliticalGroup;
import dcc.mbg.model.MEnterpriseOperation;
import dcc.mbg.model.MResume;
import dcc.service.CommonService;
import dcc.tools.BeanFactory;

public class EnterpriseOperationPanel extends JPanel implements
		TablePanel.Command {

	private TablePanel<MEnterpriseOperation> tablePanel;

	public EnterpriseOperationPanel() {
		this.tablePanel = new TablePanel<MEnterpriseOperation>(this);
		initLayout();

		String[] headers = new String[] { "\u4F01\u4E1A\u540D\u79F0",
				"\u7ECF\u8425\u4E1A\u52A1", "\u6CE8\u518C\u8D44\u91D1",
				"\u767B\u8BB0\u7C7B\u578B" };
		String[] fields = new String[] { "name", "business", "fund", "type" };
		List<MEnterpriseOperation> list = new ArrayList<MEnterpriseOperation>();
		tablePanel.setHeader(headers, fields, "id");
		tablePanel.setData(list);
	}

	private void initLayout() {

		GridBagLayout gbl = new GridBagLayout();
		gbl.columnWidths = new int[] { 25, 0, 50, 0 };
		gbl.rowHeights = new int[] { 25, 0, 50, 0 };
		gbl.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
		gbl.rowWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
		this.setLayout(gbl);

		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(0, 0, 5, 5);
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 1;
		gbc_panel.gridy = 1;
		this.add(tablePanel, gbc_panel);
	}

	@Override
	public void deleteRow(int id) {
		((CommonService) BeanFactory.getBean("commonService"))
				.deleteMEnterpriseOperation(id);
	}

	public List<MEnterpriseOperation> getData() {
		return this.tablePanel.getData();
	}

	public void update() {
		this.tablePanel.update();
	}

	@Override
	public Object addRow() {
		return new MEnterpriseOperation();
	}

	@Override
	public void resetWidth(JTable table) {

	}
	
	public void setData(List<MEnterpriseOperation> list) {
		tablePanel.setData(list);
	}
}
